#include "stdafx.h"
#include "CameraMan.h"
#include "PropertyManager.hpp"

const float ROTATE_SPEED = 0.1f;
const float MOVE_SPEED = 100.0f;

CameraMan::CameraMan( Ogre::SceneManager* creator, const Ogre::String& name,
	Ogre::Camera* camera, const Ogre::Vector3& position, const Ogre::Vector3& direction):
	SceneNode(creator, name), camera(camera), goingForward(false), goingBack(false),
		goingLeft(false), goingRight(false)
{
	SceneNode::setPosition(position);
	Agent::setPosition(position);
	setDirection(direction, TS_WORLD);
	creator->getRootSceneNode()->addChild(this);
	attachObject(camera);
}

CameraMan::~CameraMan()
{
	
}

void CameraMan::changeLookingDirection( int dx, int dy )
{
	pitch(Ogre::Degree(dy * ROTATE_SPEED), Ogre::Node::TS_LOCAL);
	yaw(Ogre::Degree(dx * ROTATE_SPEED), Ogre::Node::TS_WORLD);
}

vec3 CameraMan::calcSteeringForce(float dt)
{
	Ogre::Vector3 dir = Ogre::Vector3::ZERO;
	if (goingForward)
		dir.z = -1;
	else if (goingBack)
		dir.z = 1;

	if (goingLeft)
		dir.x = -1;
	else if (goingRight)
		dir.x = 1;

	dir = getOrientation() * dir;
	return dir.normalisedCopy() * PM.forceScale->getRealValue();
}

void CameraMan::update(float dt)
{
	Agent::update(dt);
	SceneNode::setPosition(Agent::getPosition());
}

